#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAXLINE 80

int main(void)
{
    int n;
    int fd[2];
    pid_t pid;
    char *message = "Hello, world!\n";
    char line[MAXLINE] = {0};

    if (pipe(fd) < 0) {
        perror("pipe");
        exit(1);
    }
    if ((pid = fork()) < 0) {
        perror("fork");
        exit(1);
    } else if (pid > 0) {
        /* parent */
        close(fd[0]);
        write(fd[1], message, strlen(message));
        wait(NULL);
    } else {
        /* child */
        close(fd[1]);
        n = read(fd[0], line, MAXLINE);
        write(STDOUT_FILENO, line, n);
    }
    return 0;
}

